<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>总部列表</title>
</head>
<body>
<form id="stationForm" method="post" action="${pageContext.request.contextPath}/station/list">
    <input type="hidden" name="pageNum" value="1" />  
    <input type="hidden" name="numPerPage" value="${collectionTO.pageSize}" />
    <input type="hidden" name="hqName" value="${searchCriteria.hqName}" />
    <input type="hidden" name="legalRepresentative" value="${searchCriteria.legalRepresentative}" />
    <input type="hidden" name="contactsName" value="${searchCriteria.contactsName}" />
    <input type="hidden" name="phoneNum" value="${searchCriteria.phoneNum}" />
    <input type="hidden" name="provinceId" value="${searchCriteria.provinceId}" />
    <input type="hidden" name="cityId" value="${searchCriteria.cityId}" />
</form>
<div class="pageHeader" id="station_search_div">
	<form onsubmit="return navTabSearch(this);" action="${pageContext.request.contextPath}/station/list" method="post">
	<div class="searchBar">
		<ul class="searchContent">
			<li>
				<label>总部名称</label>
				<input style="width:75px" type="text" name="hqName"  value="${searchCriteria.hqName}" />
			</li>
			<li>
				<label>法人/代理人</label>
				<input style="width:75px" type="text" name="legalRepresentative"  value="${searchCriteria.legalRepresentative}" />
			</li>
			<li>
				<label>联系人</label>
				<input style="width:75px" type="text" name="contactsName" value="${searchCriteria.contactsName}" />
			</li>
			<li>
				<label>电话</label>
				<input style="width:75px" type="text" name="phoneNum" value="${searchCriteria.phoneNum}" />
			</li>
		</ul>
		<ul class="searchContent">
			<li>
				<label>省份</label>
				<select data-placeholder="省份" id="provinceId" name="provinceId" class="select" >
				 <option value="">选择省份</option>
	           </select>
	          	<input type="hidden" id="old_provinceId" value="${searchCriteria.provinceId}"/>
			</li>
			<li>
				<label>城市</label>
	           <select data-placeholder="城市" name="cityId" id="cityId" class="form-control" data-rel="chosen">
	           		<option value="">选择城市</option>
	          	</select>
	           <input type="hidden" id="old_cityId" value="${searchCriteria.cityId}"/>
			</li>
		</ul>
		<div class="subBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">检索</button></div></div></li>
				<!-- <li><a class="button" href="demo_page6.html" target="dialog" mask="true" title="查询框"><span>高级检索</span></a></li> -->
			</ul>
		</div>
	</div>
	</form>
</div>


<div class="pageContent">
	<div class="panelBar">
		<div class="pages">
			<span>显示</span>
			<select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value})">
	 			<option value="5" <c:if test="${collectionTO.pageSize==5}">selected</c:if>>5</option>
	 			<option value="10" <c:if test="${collectionTO.pageSize==10}">selected</c:if>>10</option>
			</select>
			<span>条，共${totalCount}条</span>
		</div>
		<div class="pagination" targetType="navTab" totalCount="${totalCount}" numPerPage="${collectionTO.pageSize}" pageNumShown="10" currentPage="${collectionTO.pageNo}"></div>
	</div>
	<div class="panelBar">
		<ul class="toolBar">
<%-- 			<li class=""><a target="navTab" href="${pageContext.request.contextPath}/station/toAdd" class="add"><span>添加</span></a></li> --%>
<!-- 			<li class="line">line</li> -->
			<li class=""><a warn="请选择一条数据" target="navTab" href="${pageContext.request.contextPath}/station/toUpdate?stationId={sid_user}" class="edit"><span>修改</span></a></li>
			<li class="line">line</li>
			<li><a warn="请选择一条数据" title="确定要删除吗？" target="ajaxTodo" href="${pageContext.request.contextPath}/station/del?stationId={sid_user}" class="delete"><span>删除</span></a></li>
			<li class="line">line</li>
			<li><a target="navTab" href="${pageContext.request.contextPath}/station/details?stationId={sid_user}" class="icon"><span>详情</span></a></li>
		</ul>
	</div>
	<table class="table" width="100%" layoutH="116">
		<thead>
			<tr>
				<th width="100">油站总部id</th>
				<th width="100">油站总部名</th>
				<th width="100">油站站点id</th>
				<th width="110">油站站点名</th>
<!-- 				<th width="120">营业执照编号</th> -->
<!-- 				<th width="120">营业执照编号</th> -->
<!-- 				<th width="110">法人/代理人</th> -->
				<th width="80">地址</th>
				<th width="80">联系人</th>
				<th width="80">电话</th>
<!-- 				<th width="80">邮箱</th> -->
<!-- 				<th width="80">油枪数量</th> -->
<!-- 				<th width="80">油机数量</th> -->
<!-- 				<th width="80">油机品牌</th> -->
<!-- 				<th width="80">经度</th> -->
<!-- 				<th width="80">纬度</th> -->
<!-- 				<th width="80">备注</th> -->
				<th width="80">创建时间</th>
<!-- 				<th width="80">站点类别</th> -->
<!-- 				<th width="80">锁屏密码</th> -->
<!-- 				<th width="80">激活码</th> -->
<!-- 				<th width="80">激活时间</th> -->
				<th width="80"></th>
			</tr>
		</thead>
	<tbody>
		<volist id="vo" name="list">
			<c:forEach items="${collectionTO.list}" var="stationTO" varStatus="status">
				<tr id="tr_${stationTO.stationId}"  target="sid_user" rel="${stationTO.stationId}">
					<td>${stationTO.hqId}</td>
					<td>${stationTO.hqName}</td>
					<td>
						<input type="hidden" value="${stationTO.stationId}" id="stationId"/>
						${stationTO.stationId}
					</td>
					<td>${stationTO.stationName}</td>
<%-- 					<td>${stationTO.registeredName}</td> --%>
<%-- 					<td>${stationTO.registeredNumber}</td> --%>
<%-- 					<td>${stationTO.legalRepresentative}</td> --%>
					<td>${stationTO.province}${stationTO.city}${stationTO.address}</td>
					<td>${stationTO.contactsName}</td>
					<td>${stationTO.phoneNum}</td>
<%-- 					<td>${stationTO.email}</td> --%>
<%-- 					<td>${stationTO.fpCnt}</td> --%>
<%-- 					<td>${stationTO.dispenserCnt}</td> --%>
<%-- 					<td>${stationTO.dispenserBrand}</td> --%>
<%--  					<td>${stationTO.lat}</td> --%> 
<%-- 				<td>${stationTO.lng}</td> --%> 
<%-- 					<td>${stationTO.memo}</td> --%>
					<td>
						<fmt:formatDate value="${stationTO.createdTime}" type="date" dateStyle="long" />
					</td>
<%-- 					<td>${stationTO.stationType}</td> --%>
<%-- 					<td>${stationTO.password}</td> --%>
<%-- 					<td>${stationTO.activeCoding}</td> --%>
<!-- 					<td> -->
<%-- 						<fmt:formatDate value="${stationTO.activeTime}" type="date" dateStyle="long" /> --%>
<!-- 					</td> -->
					<td id="showCode">
						<a  href="javascript:;" onclick="station.create_code(${stationTO.stationId})">生成二维码</a>
					</td>
				</tr>
			</c:forEach>
			</volist>
		</tbody>
	</table>
	
</div>
</body>
<script type="text/javascript">
var station = {
		code : function(){
			var ids="";
			$("tbody").find("tr").each(function(i){
				  if(i != 0){
					  ids += ",";
				  } 
				  ids += $(this).find("#stationId").val();
			 });
			$.ajax({
				type : "post",
				url : "${pageContext.request.contextPath }/station/listCode",
				data : {ids:ids},
				dataType : "json",
				success : function(data) {
					if(data.code*1 == 200){
						$("tbody").find("tr").each(function(i){
							var tr =$(this);
							var id =$(tr).find("#stationId").val();
							$.each(data.list,function(n,bean){
								if(id == bean.stationId){
									$(tr).find("#showCode").html("<a target=\"navTab\" href=\""+bean.codeUrl+"\">查看二维码</a>");
								}
				             	 
				              });
						 });
					}else{
						alert(data.msg);
					}
				}
			});
	},
	create_code : function(stationId) {
		$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath }/station/createCode",
			data : {stationId:stationId},
			dataType : "json",
			success : function(data) {
				if(data.code*1 == 200){
					alertMsg.correct("生成成功");
					window.open(data.msg);
				}else{
					alert(data.msg);
				}
			}
		});
	}
};




$(document).ready(function () {
 	
 	var doc = $("#station_search_div");
	 var old_provinceId = $(doc).find("#old_provinceId").val();
	$.post("${pageContext.request.contextPath}/address/listProvinces", 
		   function(data){
		 if(data.code == 200){
              var result = "<option value=''>选择省份</option>";
              $.each(data.list,function(n,value){
             	 if(old_provinceId*1 == value.provinceId*1){
               		result +="<option value='"+value.provinceId+"' selected='selected'>"+value.province+"</option>";
               	}else{
                     result +="<option value='"+value.provinceId+"'>"+value.province+"</option>";
               	}
              });
              $(doc).find("#provinceId").html('');
              $(doc).find("#provinceId").append(result);
              list_city();
          }
	});
	$(doc).find("#provinceId").change(function(){list_city()});
	
	//二维码
	station.code();
});
function list_city() {
	var doc = $("#station_search_div");
	
	var provinceId = $(doc).find("#provinceId").val()
       var result = "<option value=''>选择城市</option>";
	if(provinceId == ""){
		$(doc).find("#cityId").html('');
		$(doc).find("#cityId").append(result);
		return;
	}
		$.post("${pageContext.request.contextPath}/address/listCity",{provinceId:$(doc).find("#provinceId").val()}, 
	   function(data){
   		 if(data.code == 200){
   			var old_cityId = $(doc).find("#old_cityId").val();
              $.each(data.list,function(n,value){
           	  	if(old_cityId*1 == value.cityId*1){
               		result +="<option value='"+value.cityId+"' selected='selected'>"+value.city+"</option>";
               	}else{
                     result +="<option value='"+value.cityId+"'>"+value.city+"</option>";
               	}
              });
              $(doc).find("#cityId").html('');
              $(doc).find("#cityId").append(result);
          }
	  });
}
function dialogAjaxDone(json){
    DWZ.ajaxDone(json);
    if (json.statusCode == DWZ.statusCode.ok){
        if (json.navTabId){
            navTab.reload(json.forwardUrl, {navTabId: json.navTabId});
        } else if (json.rel) {
            var $pagerForm = $("#stationForm", navTab.getCurrentPanel());
            var args = $pagerForm.size()>0 ? $pagerForm.serializeArray() : {}
            navTabPageBreak(args, json.rel);
        }
        if ("closeCurrent" == json.callbackType) {
            $.pdialog.closeCurrent();
        }
    }
}

</script>
</html>